# from model.basicModel import Model
# from model.lenModelUtil import util
from basicModel import Model
from lenModelUtil import util
import os
class lenModel(Model):
	"""
	__mean 表示根据训练集得到的参数长度均值
	__var 表示根据训练集得到的参数长度方差
	__stdev 表示根据训练集得到的参数长度标准差
	__formFlag 表示当前的训练集是否已经从文字集转换成长度集，也即是说元素由字符串类型转变为整形
	"""
	__mean=None
	__var=None
	__stdev=None
	__formFlag=None

	def __init__(self,trainingSet=None):
		if trainingSet != None:
			super().__init__(util.get_len_set(trainingSet))
			self.__formFlag=1
		else:
			super().__init__()
	def formTrainingDatas(self):
		"将训练集从文字参数集转换为参数长度数值集，必须经过这一部才能训练"
		if self.trainingSet!=None and self.__formFlag==0:
			self.trainingSet=util.get_len_set(self.trainingSet)
			self.__formFlag=1
	def train(self):
		if self.__formFlag==0:
			self.formTrainingDatas()
		if self.__formFlag==1 and self.trainingSet!=None:
			self.__var=util.get_var(self.trainingSet)
			self.__mean=util.get_mean(self.trainingSet)
			self.__stdev=util.get_stdev(self.trainingSet)
		else:
			print("缺少训练集...程序终止")
			os._exit(0)

	def predict(self,samples,realRst,pct=75):
		"""
		samples:list
		realRst:list
		pct:int
		samples、realRst两个参数应该是同样的长度
		pct表示敏感程度，在0到100之间
		"""
		if self.__mean!=None and self.__var!=None and self.__stdev!=None:
			predictRst=[]
			samples=util.get_len_set(samples)
			super().setSampleToPredict(samples)
			super().setRealResult(realRst)
			for x in samples:
				predictRst.append(util.in_chebyshevs_interval(x,self.__mean,self.__stdev,pct))
			super().setPredictResult(predictRst)
			return predictRst
		else:
			print("未进行训练...程序终止")
			os._exit(0)

	def getVar(self):
			return self.__var

	def setVar(self,var):
		if var!=None:
			self.__var=var

	def getMean(self):
		return self.__mean

	def setMean(self,mean):
		if mean!=None:
			self.__mean=mean
		
	def getStdev(self):
			return self.__stdev

	def setStdev(self,stdev):
		if stdev!=None:
			self.__stdev=stdev





if __name__ == '__main__':

	l=lenModel(['a'])
	l.devTest()